﻿using System; using HISModels.ViewModel;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using KeanuMvc.Reference;
using HIS.Utils;
using System.Reflection;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using HISModels.Entities;
using System.Net;
using System.Configuration;

namespace HIS.Controllers.Workflow {

    public class WorkFlow : HIS.Controllers.AppBaseController {

        #region Fields
        private string strAction = string.Empty;
        private string strNotification = string.Empty;
        private HISModels.Entities.SysNavigationGroup sysNavigationGroup = null;
        private HISModels.Entities.SysNavigation sysNavigation = null;
        #endregion

        #region Workflow
        public WorkFlow() {
            Data.Add("Pagetitle", "Workflow");
            Data.Add("Notification", strNotification);
        }

        [HIS.Utils.Securities.Authorization(RoleAction = "all")]
        public override void Index() {
            try {
                RenderFile("workflows\\index.html");

            } catch (Exception ex) {
                HttpContext.Current.Response.Write(ex.Message);
            }
        }

        [HIS.Utils.Securities.Authorization(RoleAction = "all")]
        public void PurchaseRequisition() {
            try {
                string ddr = GetWorkFlowTempletes();

                Data["Pagetitle"] += " :: Create Workflow Document";
                Data.Add("ddlWfTemplete",ddr);

               
            } catch (Exception ex) {
                Data["Notification"] = Helper.ErrorMessage(ex.Message);
            } finally {
                RenderFile("Workflows\\createworkflow.html");
                base.RestService.Dispose();
            }
        }

        [HIS.Utils.Securities.Authorization(RoleAction = "all")]
        public void ViewApproval() {
            try {
            } catch (Exception ex) {
                Data["Notification"] = Helper.ErrorMessage(ex.Message);
            } finally {
                RenderFile("Workflows\\actionworkflow.html");
                base.RestService.Dispose();
            }
        }
        public string GetWorkFlowTempletes()
        {
            
            StringReader stringReaderDropDown = null;
            string strResult = string.Empty;
            string Name = string.Empty;
            string strUri = "";
            strUri = Global.ServiceUriDictionary["wfmastertemplate"] + Global.ServiceUriDictionary["requestformat"];
            try
            {
                stringReaderDropDown = base.RestService.GetJson(strUri);
                List<WorkflowMasterTemplate> listSp = JsonConvert.DeserializeObject<List<WorkflowMasterTemplate>>(stringReaderDropDown.ReadToEnd());
                List<object[]> activeArr = new List<object[]>();

                activeArr.Add(new object[] { 0, Name = "Default (Organisation)" });
                //activeArr.Add(new object[] { 1, Name = "Siloam Karawaci" });
                //activeArr.Add(new object[] { 2, Name = "Siloam Bonjer" });


                foreach (WorkflowMasterTemplate item in listSp) activeArr.Add(new object[] { item.Id, Name = item.NameValue });

                strResult = KeanuMvc.Reference.Html.DropDown("IdHospital", string.Empty, activeArr, "");
                activeArr.Clear();
                activeArr = null;
            }
            catch
            {
            }
            finally
            {
                // stringReaderDropDown.Dispose();
            }
            return strResult;
        
        }

        #endregion

    }

}